package optimizers.commons.evaluator;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.PrintWriter;
import java.util.ArrayList;

import fitness.FastStrongOscillatorFitness;
import fitness.MathFitness;

import optimizers.ganeat.Individual;
import optimizers.ganeat.Species;

public class Test {

	/**
	 * @param args
	 * @throws IOException
	 * @throws ClassNotFoundException
	 */
	public static void main(String[] args) throws IOException,
			ClassNotFoundException {
		// TODO Auto-generated method stub
		FileInputStream readFile;
		readFile = new FileInputStream(
				"C:\\Users\\Huy\\workspace_new\\SB_Project_Stable\\result\\pref_Math_2014_08_22 00_09_38\\log");
		ObjectInputStream restore = new ObjectInputStream(readFile);
		ArrayList<ArrayList<Species>> speciesVisualData = (ArrayList<ArrayList<Species>>) restore
				.readObject();
		for (int i = 0; i < speciesVisualData.size(); i++) {
			ArrayList<Species> perGenerationSpecies = speciesVisualData.get(i);
			System.out.println("Generation " + i + ":"
					+ perGenerationSpecies.size() + " species");
			for (int j = 0; j < perGenerationSpecies.size(); j++) {
				Species species = perGenerationSpecies.get(j);
				System.out.println("Species "
						+ species.getName()
						+ ":"
						+ species.getBestIndividual().fitnessResult
								.finalResult());
			}
		}
		Individual individual = speciesVisualData.get(71).get(7)
				.getBestIndividual();
		System.out.println(individual.fitnessResult
						.finalResult());
		FileOutputStream saveFile = null;
		saveFile = new FileOutputStream("evaluator");
		ObjectOutputStream save = new ObjectOutputStream(saveFile);
		save.writeObject(new FastStrongOscillatorFitness());
		save.close();
		saveFile.close();
		saveFile = new FileOutputStream("indiv");
		save = new ObjectOutputStream(saveFile);
		save.writeObject(individual.getOligoModel());
		save.close();
		saveFile.close();
		

	}

}
